package com.sayimo.maker.mall.goods.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sayimo.framework.database.mybatis.AbstractMybatisBaseDao;
import com.sayimo.framework.exception.DaoException;
import com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao;
import com.sayimo.maker.mall.goods.vo.ShoppingCart;


/**
 * @Copyright (c) 2016 广东省尚一互联网有限公司
 * @Project: schoolmallapi
 * @ClassName: ShoppingCartImplDao
 * @Description: 购物车
 * @Author:	chenpy
 * @Date:	日期：2016年1月5日  时间：下午2:42:36
 * @Version 1.0.0
 */
@Repository(value="shoppingCartInterfaceImplDao")
public class ShoppingCartImplDao  extends AbstractMybatisBaseDao<ShoppingCart> implements ShoppingCartInterfaceDao{

	/**
	 * 
	 * @MethodName queryShoppingCartByCustomerId
	 * @Description 
	 * 
	 * @author chenpy
	 * @date 2016年1月5日 下午3:08:52
	 * @param 
	 * @return ShoppingCart
	 * @VERSION 1.0.0
	 */
	public ShoppingCart queryShoppingCartByCustomerId(Integer id) throws DaoException {
		return this.mybatisInterfaceBaseDao.get("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.queryShoppingCartByCustomerId", id);
	}

	/**
	 * 
	 * @MethodName insertShoppingCart
	 * @Description 添加购物车
	 * 
	 * @author chenpy
	 * @date 2016年1月5日 下午3:13:36
	 * @param 
	 * @return int
	 * @VERSION 1.0.0
	 */
	public int insertShoppingCart(ShoppingCart shoppingCart) throws DaoException {
		return this.mybatisInterfaceBaseDao.insert("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.insertShoppingCart", shoppingCart);
	}

	/**
	 * 
	 * @MethodName deleteShoppingCartById
	 * @Description 删除购物车
	 * 
	 * @author chenpy
	 * @date 2016年1月5日 下午3:14:11
	 * @param 
	 * @return int
	 * @VERSION 1.0.0
	 */
	public int batchDeleteShoppingCartByIds(List<Integer> ids) throws DaoException {
		return this.mybatisInterfaceBaseDao.delete("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.batchDeleteShoppingCartByIds", ids);
	}

	/**
	 * 
	 * @MethodName updateShoppingCartById
	 * @Description 修改购物车
	 * 
	 * @author chenpy
	 * @date 2016年1月5日 下午3:14:23
	 * @param 
	 * @return int
	 * @VERSION 1.0.0
	 */
	public int updateShoppingCartById(ShoppingCart shoppingCart) throws DaoException {
		return this.mybatisInterfaceBaseDao.update("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.updateShoppingCartById", shoppingCart);
	}

	/**
	 * 
	 * @MethodName queryShoppingCartByGoodsId
	 * @Description 判断购物车中是否存在指定商品
	 * 
	 * @author chenpy
	 * @date 2016年1月5日 下午3:14:32
	 * @param 
	 * @return ShoppingCart
	 * @VERSION 1.0.0
	 */
	public ShoppingCart queryShoppingCartByGoodsId(ShoppingCart shoppingCart) throws DaoException {
		return this.mybatisInterfaceBaseDao.get("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.queryShoppingCartByGoodsId", shoppingCart);
	}
	
	/**
	 * 
	* @Title: getShoppingCartList 
	* @Description: 购物车列表
	* @param customerId
	* @param providerId
	* @return
	* @throws DaoException
	* @return List<ShoppingCart>
	* @throws
	 */
	public List<ShoppingCart> getShoppingCartList(Integer customerId,Integer providerId,Integer mallType) throws DaoException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("customerId", customerId);
		map.put("providerId", providerId);
		map.put("mallType", mallType);
		return this.mybatisInterfaceBaseDao.query("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.getShoppingCartList", map);
	}
	
	
	/**
	 * 
	* @Title: getShoppingCartGoodsProviders 
	* @Description: 获取用户 购物车商品的供应商
	* @param customerId
	* @return
	* @throws DaoException
	* @return List
	* @throws
	 */
	@Override
	public List getShoppingCartGoodsProviders(Integer customerId,Integer mallType)
			throws DaoException {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("customerId", customerId);
		map.put("mallType", mallType);
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.getShoppingCartGoodsProviders",map);
	}
	
	@Override
	public int deleteShoppingCartByCartId(Integer cartId) throws DaoException {
		
		return this.mybatisInterfaceBaseDao.delete(
				"com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.batchDeleteShoppingCartByCartId", cartId);
	}
	
	/** 
	  * @package com.sayimo.school.mall.module.goods.dao
	  * @author chenpy
	  * @Title:  queryOverDueShoppingCartIds
	  * @Description: 查询时间超过半个月的购物车
	  * @param 
	  * @throws 
	  * @return String
	  * @date 2016年10月11日
	  */ 
	public String queryOverDueShoppingCartIds() throws DaoException{
		Object o = this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.queryOverDueShoppingCartIds", null);
		return o == null ? "" : o.toString();
	}
	
	/** 
	  * @package com.sayimo.school.mall.module.goods.dao
	  * @author chenpy
	  * @Title:  dropShoppingCartNormsValuesByCartIds
	  * @Description: 删除时间超过半个月的购物车商品信息
	  * @param 
	  * @throws 
	  * @return int
	  * @date 2016年10月11日
	  */ 
	public int dropShoppingCartNormsValuesByCartIds(String cartIds) throws DaoException{
		return this.mybatisInterfaceBaseDao.delete("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.dropShoppingCartNormsValuesByCartIds", cartIds);
	}
	
	/** 
	  * @package com.sayimo.school.mall.module.goods.dao
	  * @author chenpy
	  * @Title:  dropShoppingCartByIds
	  * @Description: 删除时间超过半个月的购物车商品信息
	  * @param 
	  * @throws 
	  * @return int
	  * @date 2016年10月11日
	  */ 
	public int dropShoppingCartByIds(String ids) throws DaoException{
		return this.mybatisInterfaceBaseDao.delete("com.sayimo.maker.mall.goods.dao.ShoppingCartInterfaceDao.dropShoppingCartByIds", ids);
	}
}
